﻿using System;

namespace NodeBasedSkillEditor
{
    public static partial class DAGHelper
    {
        #region const
        public const uint MinNodeId = 0x1;
        public const uint MaxNodeId = 0xfffff;
        public const uint NodeIdBits = 0xfffff000;
        public const int NodeIdBitsOffset = 12;

        public const uint MinPortId = 0x1;
        public const uint MaxPortId = 0xfff;
        public const uint PortIdBits = 0xfff;

        public const int InvalidTypeGroupId = -1;
        public const uint EmptyContextId = 0;
        public const uint InvalidNodeId = 0;

        public const string CateName_Math = "Math";
        public const string CateName_MathLogic = "Math Logic";
        public const string CateName_MathTri = "Math Trigonometry";
        public const string CateName_MathVec = "Math Vector";
        public const string CateName_Convert = "Convert";
        public const string CateName_Data = "Data";
        public const string CateName_Execution = "Execution";
        public const string CateName_Entry = "Entry";
        public const string CateName_GameEvent = "Game Event";
        public const string CateName_List = "List";

        #endregion

        public static uint OriginNodeId_To_ValidNodeId(uint originNodeId)
        {
            return Math.Clamp(originNodeId, MinNodeId, MaxNodeId) << NodeIdBitsOffset;
        }

        public static uint OriginPortId_To_ValidLocalPortId(uint originPortId)
        {
            return Math.Clamp(originPortId, MinPortId, MaxPortId);
        }

        public static uint GetNodeIdFromPortGlobalId(uint portGlobalId)
        {
            return portGlobalId & NodeIdBits;
        }

        public static uint PortGlobalId_To_PortLocalId(uint portGlobalId)
        {
            return portGlobalId & PortIdBits;
        }

        public static uint PortLocalId_To_PortGlobalId(uint nodeId, uint portLocalId)
        {
            return nodeId | portLocalId;
        }


    }
}
